package com.test.utils;

import org.javatuples.Pair;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

public class ScheduleUtil {

    /**
     * 计算整备时长
     *
     * @param startLdt
     * @param endLdt
     * @param ckServicing 送车整备时长
     * @param rkServicing 取车整备时长
     * @return
     */
    public static Pair<LocalDateTime, LocalDateTime> genScheduleTime(LocalDateTime startLdt, LocalDateTime endLdt, BigDecimal ckServicing, BigDecimal rkServicing) {
        LocalDateTime sLdt, eLdt;
        // 计算开始时间
        if (ckServicing.compareTo(BigDecimal.ZERO) == 0) {
            sLdt = startLdt;
        } else {
            int ckMinutes = ckServicing.multiply(new BigDecimal("60")).intValue();
            sLdt = DateUtil.ldtMinus(startLdt, ChronoUnit.MINUTES, ckMinutes);
        }
        // 计算结束时间
        if (ckServicing.compareTo(BigDecimal.ZERO) == 0) {
            eLdt = endLdt;
        } else {
            int rkMinutes = rkServicing.multiply(new BigDecimal("60")).intValue();
            eLdt = DateUtil.ldtPlus(endLdt, ChronoUnit.MINUTES, rkMinutes);
        }
        // 返回元组
        return Pair.with(sLdt, eLdt);
    }

    public static void main(String[] args) {
        String pattern = "yyyy-MM-dd HH:mm:ss";
        LocalDateTime startLdt = DateUtil.parseLdt("2022-01-01 00:00:00", pattern);
        LocalDateTime endLdt = DateUtil.parseLdt("2022-01-31 00:00:00", pattern);
        BigDecimal ckServicing = new BigDecimal("0.1");
        BigDecimal rkServicing = new BigDecimal("0.1");
        Pair<LocalDateTime, LocalDateTime> p = genScheduleTime(startLdt, endLdt, ckServicing, rkServicing);
        System.out.println(DateUtil.format(p.getValue0(), pattern));
        System.out.println(DateUtil.format(p.getValue1(), pattern));


        String s = "FZDA757240755273089117_1";

        String regex = "[a-zA-Z]";
        s = s.replaceAll(regex, "");
        System.out.println(s);

    }
}
